package com.duobao.controller;

import com.duobao.entity.pojo.UserInfo;
import com.duobao.entity.vo.Result;
import com.duobao.entity.vo.ResultCodeEnum;
import com.duobao.interceptor.AuthContextUtil;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 访问控制
 * todo 权限控制,后期需要根据数据库返回对应数据,目前先写死
 */
@RestController
@Tag(name = "访问控制接口")
@RequestMapping("/access")
public class AccessController {

    /**
     * 获取用户可访问功能
     */
    @GetMapping("/getAccess")
    public Result getAccess() {
        UserInfo userInfo = AuthContextUtil.getUserInfo();
        if (userInfo.getType() == 0) {
            // 普通

            String json = "[" +
                    "{\"function\":\"扫码\"" + "," +
                    "\"icon\":\"scan\"" + "," +
                    "\"link\": \"/scanQR\"}" + "," +
                    "{\"function\":\"工资统计\"" + "," +
                    "\"icon\":\"balance-o\"" + "," +
                    "\"link\": \"/wageStatistics\"}" + "," +
                    "{\"function\":\"考勤\"" + "," +
                    "\"icon\":\"location-o\"" + "," +
                    "\"link\": \"/attendance\"}"+ "," +
                    "{\"function\":\"匿名举报\"" + "," +
                    "\"icon\":\"warn-o\"" + "," +
                    "\"link\": \"/report\"}"+ "," +
                    "{\"function\":\"薪酬管理\"" + "," +
                    "\"icon\":\"balance-o\"" + "," +
                    "\"link\": \"/salaryAdministration\"}"
                    + "]";
            // 将json变为字符串

            return Result.success(json, ResultCodeEnum.SUCCESS);
        }else {
            String json = "[" +
                    "{\"function\":\"薪酬管理\"" + "," +
                    "\"icon\":\"balance-o\"" + "," +
                    "\"link\": \"/salaryAdministration\"}" + "," +
                    "{\"function\":\"人员管理\"" + "," +
                    "\"icon\":\"friends-o\"" + "," +
                    "\"link\": \"/personnelManagement\"}" + "," +
                    "{\"function\":\"工序管理\"" + "," +
                    "\"icon\":\"completed-o\"" + "," +
                    "\"link\": \"/wageStatistics\"}" + "," +
                    "{\"function\":\"考勤管理\"" + "," +
                    "\"icon\":\"guide-o\"" + "," +
                    "\"link\": \"/wageStatistics\"}"
                    + "]";
            // 管理员
            return Result.success(json, ResultCodeEnum.SUCCESS);
        }
    }
}
